package com.htt.bms.common;

import java.io.Serializable;

/**
 * @author 侯婷婷
 * @version 1.0
 * @description 包装类
 */
public class Wrapper<T> implements Serializable {
    
    //成功码
    public static final int SUCCESS_CODE = 200;
    
    //成功信息
    public static final String SUCCESS_MESSAGE = "操作成功";
    
    //错误码
    public static final int ERROR_CODE = 500;
    
    //错误信息
    public static final String ERROR_MESSAGE = "系统异常,请稍后重试!";

    //错误码，参数非法
    public static final int ILLEGAL_ARGUMENT_CODE_ = 400;
    
    //错误信息，参数非法
    public static final String ILLEGAL_ARGUMENT_MESSAGE = "请求参数非法，请核查！";

    //用户凭证非法
    public static final int AUTHORIZATION_CODE = 403;

    //凭证非法信息
    public static final String AUTHORIZATION_MESSAGE = "用户凭证已过期，请重新登录！";

    //编号
    private int code;
    
    //信息 
    private String message;
    
    //结果数据
    private T result;

    //200+操作成功
    public Wrapper(){
        this(SUCCESS_CODE, SUCCESS_MESSAGE);
    }

    //code+message
    public Wrapper(int code, String message){
        this.code(code).message(message);
    }

    //code+message+result
    public Wrapper(int code, String message, T result){
        super();
        this.code(code).message(message).result(result);
    }

    public int getCode(){
        return code;
    }

    public void setCode(int code){
        this.code = code;
    }

    public String getMessage(){
        return this.message;
    }

    public void setMessage(String message){
        this.message = message;
    }

    public T getResult(){
        return result;
    }

    public void setResult(T result){
        this.result = result;
    }

    public Wrapper<T> code(int code){
        this.code = code;
        return this;
    }

    public Wrapper<T> message(String message){
        this.setMessage(message);
        return this;
    }

    public Wrapper<T> result(T result){
        this.setResult(result);
        return this;
    }

    @Override
    public String toString() {
        return "Wrapper={" +
                "code=" + code +
                ", message=" + message +
                ", result=" + result +
                "}";
    }

    public boolean isSuccess(){
        return this.code == Wrapper.SUCCESS_CODE;
    }

    public boolean isFalse(){
        return !isSuccess();
    }
}
